package com.basic.library.adapter;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import java.util.List;

public abstract class RCommonAdapter<T> extends RecyclerView.Adapter<ViewHolder> {
	protected Context mContext;
	protected int mLayoutId;
	protected List<T> mDatas;
	protected LayoutInflater mInflater;

	public RCommonAdapter(Context context, int layoutId, List<T> datas) {
		mContext = context;
		mInflater = LayoutInflater.from(context);
		mLayoutId = layoutId;
		mDatas = datas;
	}

	@Override
    public ViewHolder onCreateViewHolder(final ViewGroup parent, int viewType)
    {
        ViewHolder viewHolder = RViewHolder.get(mContext, parent, mLayoutId);
        return viewHolder;
    }

	@Override
	public void onBindViewHolder(ViewHolder holder, int position) {
		convert((RViewHolder)holder, mDatas.get(position));
	}

	public abstract void convert(RViewHolder holder, T t);

	@Override
	public int getItemCount() {
		return mDatas.size();
	}
}
